package it.fc.action.giocatori;

import it.fc.action.FcAction;
import it.fc.bean.SquadraBean;
import it.fc.service.interfaces.IDbService;

import org.apache.log4j.Logger;

public class SaveSquadraAction extends FcAction {

    private static final Logger log              = Logger.getLogger(SaveSquadraAction.class);
    private static final long   serialVersionUID = -4618800181687630993L;
    private String              nome;

    @Override
    public String execute() throws Exception {

        log.debug("Salvataggio squadra ... " + getNome());

        IDbService dbManager = getDbService();

        if (getIdUser() > 0) {
            SquadraBean team = dbManager.getSquadraByName(getNome());
            if (team != null) {
                addActionError(getText("gestione.err"));
                return INPUT;
            } else {
                dbManager.insertSquadra(getIdUser(), getNome());
            }
        }

        return SUCCESS;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public String getNome() {
        return nome;
    }

}
